

#include <iostream>

using namespace std;

// 菱形继承

class A
{
public:
    A(int a = 0)
        :_a(a)
    {}

protected:
    int _a;
};

class B : virtual public A
{
public:
    B(int a = 0, int b = 0)
        :A(a)
         ,_b(b)
    {}

protected:
    int _b;
};

class C : virtual public A
{
public:
    C(int a = 0, int c = 0)
        :A(a)
         ,_c(c)
    {}

protected:
    int _c;
};

class D : public B, public C
{
public:

    D(int a = 0, int b = 0, int c = 0, int d = 0)
        :B(a, b)
         ,C(a, c)
         ,_d(d)
    {}

    void print()
    {
        // 加 virtual 后
        cout << _a << ' ' << B::_a << ' ' << C::_a << ' ' << _b << ' ' << _c << ' ' << _d << endl;

        //cout << B::_a << ' ' << C::_a << ' ' << _b << ' ' << _c << ' ' << _d << endl;
    }

protected:
    int _d;
};

int main()
{
    D d(1,2,3,4);
    
    d.print();

    D d1(100,222,333,444);
    d1.print();

    return 0;
}
